<span page-title ng-model="product">{{ 'Repositories for Product:' | translate }} {{ product.name }}</span>

<div data-extend-template="layouts/partials/table.html">
  <div data-block="list-actions">
    <button type="button" class="btn btn-default"
            ui-sref="product.repositories.new({productId: product.id})"
            ng-hide="!product.$resolved || denied('edit_products', product) || product.redhat">
      <span translate>New Repository</span>
    </button>

    <button type="button" class="btn btn-default"
            ng-click="syncSelectedRepositories()"
            ng-hide="denied('sync_products', product)"
            ng-disabled="syncInProgress || table.numSelected == 0">
      <span translate>Sync Now</span>
    </button>

    <button type="button" class="btn btn-default"
            ng-click="openModal()"
            ng-show="product.$resolved && canRemoveRepositories(product)"
            ng-disabled="removingRepositories || table.numSelected == 0">
      <span ng-show="removingRepositories">
        <i class="fa fa-spinner inline-icon fa-spin"></i>
        <span>{{ "Removing Repositories" | translate }}</span>
      </span>
      <span ng-hide="removingRepositories">
        {{ "Remove Repositories" | translate }}
      </span>
    </button>

    <div bst-modal="removeSelectedRepositories()" model="table">
      <div data-block="modal-header"
           translate
           translate-n="table.numSelected"
           translate-plural="Remove {{ table.numSelected }} repositories?">
        Remove repository?
      </div>
      <div data-block="modal-body"
           translate
           translate-n="table.numSelected"
           translate-plural="Are you sure you want to remove {{ table.getSelected().length }} repositories?">
        Are you sure you want to remove the {{ table.getSelected()[0].name }} repository?
      </div>
    </div>

    <span ng-switch="getRepositoriesNonDeletableReason(product)" bst-feature-flag="custom_products">
      <i class="fa fa-question-sign" ng-switch-when="permissions"
         uib-tooltip="{{ 'You cannot remove these repositories because you do not have permission.' | translate }}"
         tooltip-animation="false"
         tooltip-placement="left"
         tooltip-append-to-body="true">
      </i>
      <i class="fa fa-question-sign" ng-switch-when="redhat"
         uib-tooltip="{{ 'You cannot remove these repositories because they belong to a Red Hat product.' | translate }}"
         tooltip-animation="false"
         tooltip-placement="left"
         tooltip-append-to-body="true">
      </i>
    </span>
  </div>

  <span data-block="no-rows-message" translate>
    You currently don't have any Repositories included in this Product, you can add Repositories using the button on the right.
  </span>

  <span data-block="no-search-results-message" translate>
    Your search returned zero Repositories.
  </span>

  <div data-block="table">
    <table class="table table-striped table-bordered">
      <thead>
        <tr bst-table-head row-select>
          <th bst-table-column="name" translate>Name</th>
          <th bst-table-column="type" translate>Type</th>
          <th bst-table-column="sync-status" translate>Sync Status</th>
          <th bst-table-column="content" translate>Content</th>
        </tr>
      </thead>

      <tbody>
        <tr bst-table-row
            row-select="repository"
            ng-repeat="repository in table.rows | filter:repositorySearch">
          <td bst-table-cell>
            <a ui-sref="product.repository.info({productId: product.id, repositoryId: repository.id})">{{ repository.name }}</a>
          </td>
          <td bst-table-cell>{{ repository.content_type }}</td>
          <td bst-table-cell>
            <span ng-show="repository.url">
              <span ng-show="repository.last_sync == null && repository.last_sync_words == null" translate>
                Not Synced
              </span>
              <span ng-show="repository.last_sync == null && repository.last_sync_words" translate>
                Completed {{ repository.last_sync_words }} ago
              </span>
              <span ng-show="repository.last_sync !== null && repository.last_sync.ended_at == null" translate>
                <a href="/foreman_tasks/tasks/{{repository.last_sync.id}}">{{ repository.last_sync.result | capitalize}}</a>
              </span>
              <span ng-hide="repository.last_sync == null || repository.last_sync.ended_at == null">
                <a href="/foreman_tasks/tasks/{{repository.last_sync.id}}">{{ repository.last_sync.result | capitalize}}</a>
                <span translate>{{ repository.last_sync_words }} ago</span>
              </span>
            </span>
            <span ng-hide="repository.url" translate>N/A</span>
          </td>
          <td bst-table-cell>
            <span ng-show="repository.content_type == 'yum'">
              <div>
                <a translate ui-sref="product.repository.manage-content.packages({productId: product.id, repositoryId: repository.id})">
                  {{ repository.content_counts.rpm || 0 }} Packages
                </a>
              </div>

              <div>
                <span translate ng-show="repository.content_counts.srpm > 0">
                  {{ repository.content_counts.srpm }} Source RPMs
                </span>
              </div>

              <div>
                <a ui-sref="errata({repositoryId: repository.id})" translate>
                  {{ repository.content_counts.erratum || 0 }} Errata
                </a>
              </div>

              <div>
                <a ui-sref="product.repository.manage-content.package-groups({productId: product.id, repositoryId: repository.id})">
                  {{ repository.content_counts.package_group || 0 }} Package Groups
                </a>
              </div>
              <div>
                <a ui-sref="product.repository.manage-content.module-streams({productId: product.id, repositoryId: repository.id})">
                  {{ repository.content_counts.module_stream || 0 }} Module Streams
                </a>
              </div>
            </span>

            <span ng-show="repository.content_type == 'docker'">
              <div>
                <a ui-sref="product.repository.manage-content.docker-manifests({productId: product.id, repositoryId: repository.id})" translate>
                  {{ repository.content_counts.docker_manifest || 0 }} Container Image Manifests
                </a>
              </div>
              <div>
                <a ui-sref="product.repository.manage-content.docker-manifest-lists({productId: product.id, repositoryId: repository.id})" translate>
                  {{ repository.content_counts.docker_manifest_list || 0 }} Container Image Manifest Lists
                </a>
              </div>
              <div>
                <a ui-sref="product.repository.manage-content.docker-tags({productId: product.id, repositoryId: repository.id})" translate>
                  {{ repository.content_counts.docker_tag || 0 }} Container Image Tags
                </a>
              </div>
            </span>

            <span ng-show="repository.content_type == 'ostree'">
              <div>
                <span translate>
                  {{ repository.content_counts.ostree_branch || 0 }} OSTree Branches
                </span>
              </div>
            </span>

            <span ng-show="repository.content_type == 'file'">
              <div>
                <span translate>
                  {{ repository.content_counts.file || 0 }} Files
                </span>
              </div>
            </span>

            <span ng-show="repository.content_type == 'deb'">
              <div>
                <a translate ui-sref="product.repository.manage-content.debs({productId: product.id, repositoryId: repository.id})">
                  {{ repository.content_counts.deb || 0 }} deb Packages
                </a>
              </div>
            </span>

            <span ng-show="repository.content_type == 'ansible_collection'">
              <div>
                <a translate ui-sref="product.repository.manage-content.ansible-collections({productId: product.id, repositoryId: repository.id})">
                  {{ repository.content_counts.ansible_collection || 0 }} Ansible Collections
                </a>
              </div>
            </span>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</div>

